package com.newzqxq.koalamoney.ui.activity;

import android.content.res.Resources;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.util.TypedValue;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.newzqxq.koalamoney.R;
import com.newzqxq.koalamoney.common.BaseActivity;
import com.newzqxq.koalamoney.common.BaseFragment;
import com.newzqxq.koalamoney.common.Params;
import com.newzqxq.koalamoney.ui.adapter.MFViewPagerAdapter;
import com.newzqxq.koalamoney.ui.fragment.ExitFragment;
import com.newzqxq.koalamoney.ui.fragment.HoldFragment;
import com.newzqxq.koalamoney.utils.StatusBarUtil;
import com.newzqxq.koalamoney.utils.TabLayoutUtils;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 我的理财
 */

public class MyFinancialActivity extends BaseActivity {

    @BindView(R.id.title_mid_tv)
    TextView title_mid_tv;
    @BindView(R.id.mf_tabLayout)
    TabLayout mf_TabLayout;
    @BindView(R.id.mf_viewPager)
    ViewPager mf_ViewPager;

    MFViewPagerAdapter adapter;
    private String[] titles = new String[]{"持有中(0)", "已退出(0)"};
    private String[] titlesCode = new String[]{"hold", "exit"};

    @Override
    protected int getContentViewId() {
        return R.layout.ui_myfinancial;
    }

    @Override
    protected void initData() {
        setTitle();
        LinearLayout linearLayout = (LinearLayout) mf_TabLayout.getChildAt(0);
        linearLayout.setBackgroundColor(getResources().getColor(R.color.white));
        // 在所有子控件的中间显示分割线（还可能只显示顶部、尾部和不显示分割线）
        linearLayout.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
        // 设置分割线的距离本身（LinearLayout）的内间距
        linearLayout.setDividerPadding(40);
        // 设置分割线的样式
        linearLayout.setDividerDrawable(ContextCompat.getDrawable(this, R.drawable.divider_vertical));
        mf_TabLayout.post(new Runnable() {
            @Override
            public void run() {
                TabLayoutUtils.setIndicator(mf_TabLayout, 60, 60);
            }
        });


        List<BaseFragment> fragments = new ArrayList<>();
        HoldFragment fHold = new HoldFragment();
        ExitFragment fExit = new ExitFragment();
        Bundle bundle = new Bundle();
        bundle.putString(Params.DATA, titlesCode[0]);
        fHold.setArguments(bundle);
        fExit.setArguments(bundle);
        fragments.add(fHold);
        fragments.add(fExit);
        adapter = new MFViewPagerAdapter(getSupportFragmentManager(), fragments, titles);
        mf_ViewPager.setAdapter(adapter);
        mf_ViewPager.setOffscreenPageLimit(titles.length);
        mf_TabLayout.setupWithViewPager(mf_ViewPager);
    }

    //title
    private void setTitle() {
        title_mid_tv.setText(R.string.my_financial);
    }

    //关闭当前
    @OnClick(R.id.title_relative_back)
    void ShutDown() {
        finish();
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initListener() {

    }

    @Override
    protected void clearMemory() {

    }


}
